package com.example.demo.controller.task;

import com.example.demo.service.task.TaskService;
import com.example.demo.vo.ResultVO;
import com.example.demo.vo.report.ReportCoNumVO;
import com.example.demo.vo.report.ReportSimNumVO;
import com.example.demo.vo.task.TaskDocVO;
import com.example.demo.vo.task.TaskSimpleVO;
import com.example.demo.vo.task.TaskVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {
    @Resource
    private TaskService taskService;

    @GetMapping("/validTaskSimple")
    public ResultVO<List<TaskSimpleVO>> getValidTaskSimple(@RequestParam int pageNum){
        return taskService.getValidTaskSimple(pageNum);
    }

    @GetMapping("/allTaskSimple")
    public ResultVO<List<TaskSimpleVO>> getALLTaskSimple(@RequestParam int pageNum){
        return taskService.getAllTaskSimple(pageNum);
    }

    @GetMapping("/taskById")
    public ResultVO<TaskVO> getTaskByTaskId(@RequestParam int tid){
        return taskService.getTaskByTaskId(tid);
    }

    @GetMapping("/taskSimpleByWorker")
    public ResultVO<List<TaskSimpleVO>> getTaskSimpleByWorker(@RequestParam String username,@RequestParam int pageNum){
        return taskService.getTaskSimpleByWorker(username,pageNum);
    }

    @GetMapping("/getTaskSimpleByEmployer")
    public ResultVO<List<TaskSimpleVO>> getTaskSimpleByEmployer(@RequestParam String username,@RequestParam int pageNum){
        return taskService.getTaskSimpleByEmployer(username,pageNum);
    }

    @PostMapping("/uploadDoc")
    public ResultVO<TaskDocVO> uploadDoc(@RequestParam("file") MultipartFile doc){
        return taskService.uploadDoc(doc);
    }

    @GetMapping("/download/{originName:.+}")
    public void download(@PathVariable String originName, @RequestParam String newName, HttpServletResponse response) {
        taskService.downloadFile(originName, newName, response);
    }

    @PostMapping("/uploadTask")
    public ResultVO<TaskVO> uploadTask(@RequestBody TaskVO taskVO){
        return taskService.uploadTask(taskVO);
    }

    @GetMapping("/getAllCoreportNumByTid")
    public ResultVO<List<ReportCoNumVO>> getAllCoreportNumByTid(@RequestParam("tid")int tid){
        return taskService.getAllCoreportNumByTid(tid);
    }

    @GetMapping("/getAllSimilarityNumByTid")
    public ResultVO<List<ReportSimNumVO>> getAllSimilarityNumByTid(@RequestParam("tid")int tid,@RequestParam("min")int min,@RequestParam("max")int max){
        return taskService.getAllSimilarityNumByTid(tid,min,max);
    }
}
